
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */




package controller;




import bo.BUS_SanPham;
import com.opensymphony.xwork2.ActionSupport;
import dto.DTO_SanPham;
import java.util.ArrayList;



/**

 *

 * @author BarcelonaFC

 */



public class QLSanPhamAction extends ActionSupport {

     private ArrayList<DTO_SanPham>  dssp;
    private String chon;
    private String gtTimKiem;


    private String TenSP;
    private int GiaMua;
    private int GiaBan;
    private int LoaiSP;
    private int ChuDe;
    private int GioiTinh;
    private String HinhAnh;
    private String ThongTin;

    public int getChuDe() {
        return ChuDe;
    }

    public void setChuDe(int ChuDe) {
        this.ChuDe = ChuDe;
    }

    public int getGiaBan() {
        return GiaBan;
    }

    public void setGiaBan(int GiaBan) {
        this.GiaBan = GiaBan;
    }

    public int getGiaMua() {
        return GiaMua;
    }

    public void setGiaMua(int GiaMua) {
        this.GiaMua = GiaMua;
    }

    public int getGioiTinh() {
        return GioiTinh;
    }

    public void setGioiTinh(int GioiTinh) {
        this.GioiTinh = GioiTinh;
    }

    public String getHinhAnh() {
        return HinhAnh;
    }

    public void setHinhAnh(String HinhAnh) {
        this.HinhAnh = HinhAnh;
    }

    public int getLoaiSP() {
        return LoaiSP;
    }

    public void setLoaiSP(int LoaiSP) {
        this.LoaiSP = LoaiSP;
    }




    public String getTenSP() {
        return TenSP;
    }

    public void setTenSP(String TenSP) {
        this.TenSP = TenSP;
    }

    public String getThongTin() {
        return ThongTin;
    }

    public void setThongTin(String ThongTin) {
        this.ThongTin = ThongTin;
    }

    public String getChon() {
        return chon;
    }

    public void setChon(String chon) {
        this.chon = chon;
    }

    public ArrayList<DTO_SanPham> getDssp() {
        return dssp;
    }

    public void setDssp(ArrayList<DTO_SanPham> dssp) {
        this.dssp = dssp;
    }

    public String getGtTimKiem() {
        return gtTimKiem;
    }

    public void setGtTimKiem(String gtTimKiem) {
        this.gtTimKiem = gtTimKiem;
    }




    public QLSanPhamAction() {

    }



    public String execute() throws Exception {

        if (chon.equals("1")) {
            BUS_SanPham busKH = new BUS_SanPham();
            int MaSP = Integer.parseInt(gtTimKiem);
            dssp = busKH.LoadDSSPTheoMaSP(MaSP);
        }
        if (chon.equals("2")) {
            BUS_SanPham busKH = new BUS_SanPham();
            dssp = busKH.LoadDSSPTheoTenSP(gtTimKiem);
        }
        if (chon.equals("3")) {
            BUS_SanPham busKH = new BUS_SanPham();
            dssp = busKH.LoadDSSP();
        }
        return "success";


    }

    @Override
    public void validate() {
        if (chon.equals("1")) {
            if (gtTimKiem.equals("")) {
                addActionError("Vui lòng nhập vào giá trị tìm kiếm");
                return;

            }
            try {
                int a = Integer.parseInt(gtTimKiem);

            } catch (Exception e) {
                addActionError("Dữ liệu nhập không hợp lệ");
                return;
            }
        }
        if (chon.equals("2")) {
            if (gtTimKiem.equals("")) {
                addActionError("Vui lòng nhập vào giá trị tìm kiếm");
                return;

            }

        }
     

    }



}